package com.justgame.project.service.just.service;

import com.justgame.project.cloud.common.exception.Exc;
import com.justgame.project.cloud.common.util.ObjUtil;
import com.justgame.project.service.api.dto.JustGameAdditionDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.mapper.JustGameAdditionMapper;
import com.justgame.project.service.api.vo.JustGameAdditionVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional(rollbackFor = Exception.class)
@AllArgsConstructor
public class JustGameAdditionService {

    private final JustGameAdditionMapper gameAdditionMapper;

    public PageRequest<JustGameAdditionVO> getList(PageRequest pageRequest, JustGameAdditionDTO dto) {
        pageRequest.startPage();
        return pageRequest.BuildPageInfo(gameAdditionMapper.getList(dto));
    }

    public Boolean save(JustGameAdditionDTO dto) {
        ObjUtil.inject(dto, true);
        return gameAdditionMapper.Insert(dto) > 0;
    }

    public Boolean Delete(JustGameAdditionDTO dto) {
        if (dto.getIds() == null || dto.getIds().size() == 0) {
            throw new Exc("请先选择你要删除的数据！");
        }
        ObjUtil.inject(dto, false);
        return gameAdditionMapper.Delete(dto) > 0;
    }

    public Boolean updateById(JustGameAdditionDTO dto) {
        if (!ObjUtil.checkId(dto)) throw new Exc("请重新选择后再试！");
        ObjUtil.inject(dto, false);
        return gameAdditionMapper.UpdateById(dto) > 0;
    }

}
